//
//  WDLoginPasswordView.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/8/21.
//

#import "WDLoginPasswordView.h"

@interface WDLoginPasswordView ()
@property (nonatomic, strong) UITextField *pwdTextField;
@property (nonatomic, strong) UIButton *btnShow;
@end

@implementation WDLoginPasswordView

- (void)initWithSubView {
    self.backgroundColor = [UIColor whiteColor];
    self.layer.borderColor = [UIColor colorWithHexString:@"#DDDDDD"].CGColor;
    self.layer.borderWidth = 1;
    self.layer.cornerRadius = 5;
    self.layer.masksToBounds = YES;
    
    [self initWithPwdTextField];
    
    [self initWithBtnShow];
}


- (void)initWithPwdTextField {
    if (!_pwdTextField) {
        CGRect frame = CGRectMake(22, (self.height - 32) * 0.5, self.width - 22 - 50, 32);
        _pwdTextField = [[UITextField alloc] initWithFrame:frame];
        _pwdTextField.attributedPlaceholder = [EDSUtility attributeTitle:@"请输入密码" titleColor:[UIColor colorWithHexString:@"#999999"] titleFont:[UIFont systemFontOfSize:15 weight:UIFontWeightRegular] value:@"" valueColor:[UIColor colorWithHexString:@"#999999"] valueFont:[UIFont systemFontOfSize:15 weight:UIFontWeightRegular]];
        _pwdTextField.font = [UIFont systemFontOfSize:15 weight:UIFontWeightRegular];
        _pwdTextField.textColor = kBlackColor;
        _pwdTextField.textAlignment = NSTextAlignmentLeft;
        _pwdTextField.borderStyle = UITextBorderStyleNone;
        _pwdTextField.returnKeyType = UIReturnKeyDone;
        _pwdTextField.keyboardType = UIKeyboardTypeASCIICapable;
        _pwdTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
        _pwdTextField.secureTextEntry = YES;
        [self addSubview:_pwdTextField];
    }
}

- (void)initWithBtnShow {
    if (!_btnShow) {
        CGRect frame = CGRectMake(self.pwdTextField.right + (50 - 22) * 0.5, (self.height - 22) * 0.5, 22, 22);
        _btnShow = [UIButton createWithButton:self frame:frame font:FONTSIZE(16) target:self action:@selector(actionWithShowPwd:) propertiesBlock:^(UIButton * _Nonnull button) {
            [button setImage:[UIImage imageNamed:@"ic-password-close"] forState:UIControlStateNormal];
            [button setImage:[UIImage imageNamed:@"ic-password-open"] forState:UIControlStateSelected];
        }];
    }
}

/// 是否显示密码
/// - Parameter sender: sender description
- (void)actionWithShowPwd:(id)sender {
    UIButton *btn = (UIButton *)sender;
    btn.selected = !btn.selected;
    _pwdTextField.secureTextEntry = !btn.selected;
}

//ic-password-open


@end
